package com.whfc.wxmp.api.homePage;

import com.whfc.base.dto.WeatherDTO;
import com.whfc.base.entity.AppRealtimeWeather;
import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.R;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.emp.dto.AppWarnEmpRecordDTO;
import com.whfc.emp.dto.WxEmpDataCenterDTO;
import com.whfc.entity.dto.fvs.FvsInfoDTO;
import com.whfc.entity.dto.mach.MachInfoDTO;
import com.whfc.entity.dto.msg.AppWarnMsgDTO;
import com.whfc.entity.dto.warn.WarnCountDTO;
import com.whfc.fuum.dto.AppProjectDTO;
import com.whfc.fuum.dto.AppProjectDetailDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.safety.dto.SafetyCheckListDTO;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.wxmp.api.base.service.ProjectService;
import com.whfc.wxmp.api.base.service.WxMessageService;
import com.whfc.wxmp.api.base.service.WxWeatherService;
import com.whfc.wxmp.api.emp.service.WxEmpService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 小程序2.0首页
 * @author ：pyl
 * @date ：Created in 2022/7/18 14:07
 * @description：小程序2.0首页
 */

@RestController
@RequestMapping("/mp/api/home")
public class HomePageController extends BaseController {

    @Autowired
    private WxWeatherService wxWeatherService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private WxEmpService wxEmpService;

    @Autowired
    private WxMessageService wxMessageService;
    /**
     * 2.0 获取实时天气情况
     * @param deptId
     * @return
     */
    @GetMapping("weather")
    public R<WeatherDTO> realtimeWeather(@RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取实时天气", RequestConetxtUtil.getParameters());
        return R.success(wxWeatherService.realtimeWeather(deptId));
    }
//    @GetMapping("environment")
//    public R<WeatherDTO> environment(@RequestParam("deptId") Integer deptId) {
//        //todo
//        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
//                "获取人员报警记录列表", RequestConetxtUtil.getParameters());
//        return R.success(wxWeatherService.realtimeWeather(deptId));
//    }

    /**
     * 2.0 获取人员数据在场
     * @param deptId
     * @return
     */
    @GetMapping("people")
    public R<WxEmpDataCenterDTO> people(@RequestParam("deptId") Integer deptId) {
        //todo
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取人员数据", RequestConetxtUtil.getParameters());
        WxEmpDataCenterDTO empDataCenter = wxEmpService.getEmpDataCenter(deptId);
        return R.success(empDataCenter);
    }

    /**
     * 2.0 获取项目详情
     * @param deptId
     * @return
     */
    @GetMapping("project/detail")
    public R<AppProjectDetailDTO> projectDetail(@RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取项目概况", RequestConetxtUtil.getParameters());
        AppProjectDetailDTO appProjectDetailDTO = projectService.detail(deptId);
        return R.success(appProjectDetailDTO);
    }

    /**
     * 2.0 获取项目列表
     * @param user
     * @return
     */
    @GetMapping("project/list")
    public R<AppProjectDetailDTO> projectList(@CurrentWxUser WxUser user) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取项目列表", RequestConetxtUtil.getParameters());
        List<AppProjectDetailDTO> appProjectDetailDTO = projectService.list( user);
        return R.success(appProjectDetailDTO);
    }

    /**
     * 2.0 我的应用-获取监控报警数量
     * @param deptId
     * @return
     */
    @GetMapping("warn/list")
    public R<WarnCountDTO> warnList(@RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取监控报警数量", RequestConetxtUtil.getParameters());
        WarnCountDTO appProjectDetailDTO = projectService.warnList( deptId);
        return R.success(appProjectDetailDTO);
    }

    /**
     * 2.0 安全隐患汇总
     * @param deptId
     * @return
     */
    @GetMapping("safety/list")
    public R<SafetyCheckListDTO> safeList(@RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取安全隐患汇总", RequestConetxtUtil.getParameters());
        SafetyCheckListDTO appProjectDetailDTO = projectService.safeList( deptId);
        return R.success(appProjectDetailDTO);
    }

    /**
     * 2.0 设备概况
     * @param deptId
     * @return
     */
    @GetMapping("mach")
    public R<MachInfoDTO> machInfo(@RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备概况", RequestConetxtUtil.getParameters());
        MachInfoDTO appProjectDetailDTO = projectService.machInfo( deptId);
        return R.success(appProjectDetailDTO);
    }

    /**
     * 2.0 视频监控
     * @param deptId
     * @return
     */
    @GetMapping("fvs")
    public R<FvsInfoDTO> fvsInfo(@RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}", RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取视频监控", RequestConetxtUtil.getParameters());
        FvsInfoDTO appProjectDetailDTO = projectService.fvsInfo( deptId);
        return R.success(appProjectDetailDTO);
    }


    /**
     * 2.0 获取待我处理的审批
     * @param user
     * @param
     * @return
     */
    @GetMapping("/getNewApproveWithMe")
    public R<Map> getNewApproveWithMe(@CurrentWxUser WxUser user, @RequestParam("deptId") Integer deptId) {
        logger.info("获取待我处理的审批,userPhone:{},username:{},deptId:{}", user.getPhone(),user.getName(),deptId);
        return R.success(wxMessageService.getNewApproveWithMe(user.getPhone(),deptId));
    }

}
